﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;
using System.Windows.Media;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.CodeUnit"/>.
    /// </summary>
    public class CodeUnitVM : NamespaceDeclVM
    {
        #region /* STATICS */

        internal static new void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(CodeUnit),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new CodeUnitVM((CodeUnit)codeObject, isDescription, dictionary); });
        }

        #endregion

        #region /* FIELDS */

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a new <see cref="CodeUnit"/> with the specified file name.
        /// </summary>
        public CodeUnitVM(CodeUnit codeUnit, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(codeUnit, isDescription, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.CodeUnit"/> model.
        /// </summary>
        public CodeUnit CodeUnit
        {
            get { return (CodeUnit)CodeObject; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        public override Brush BorderBrush
        {
            get { return Brushes.LightGray; }
        }

        public override Brush BackgroundBrush
        {
            get { return Brushes.White; }
        }

        protected override void RenderStatement(CodeRenderer renderer, RenderFlags flags)
        {
            if (flags.HasFlag(RenderFlags.Description))
                renderer.RenderText(CodeUnit.Name, NORMAL_BRUSH, this);
        }

        protected override void RenderAfter(CodeRenderer renderer, RenderFlags flags)
        {
            base.RenderAfter(renderer, flags | RenderFlags.SuppressNewLine);
        }

        public override void RenderToolTip(CodeRenderer renderer, RenderFlags flags)
        {
            // Don't bother displaying the type - just the file name
            renderer.RenderText(CodeUnit.FileName, NORMAL_BRUSH, TextStyle.Proportional, this);
            if (CodeUnit.IsGenerated)
            {
                renderer.NewLine();
                renderer.RenderText("(generated)", NORMAL_BRUSH, TextStyle.Proportional | TextStyle.Italic | TextStyle.Bold);
            }
            RenderMessagesInToolTip(renderer, flags);
        }

        #endregion
    }
}
